package cn.tedu.csmall.product.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Knife4j配置类
 *
 * @author Chen
 */
@Slf4j
@Configuration
public class Knife4jConfiguration {
    /**
     * 标题
     */
    private String title = "酷鲨商城在线API文档--商品管理";
    /**
     * 简介
     */
    private String description = "酷鲨商城在线API文档--商品管理";
    /**
     * 服务条款URL
     */
    private String termsOfServiceUrl = "http://www.apache.org/licenses/LICENSE-2.0";
    /**
     * 联系人
     */
    private String contactName = "白马程序员-juffin";
    /**
     * 联系网址
     */
    private String contactUrl = "https://juffin96.github.io";
    /**
     * 联系邮箱
     */
    private String contactEmail = "juffin96@gmail.com";
    /**
     * 版本号
     */
    private String version = "0.0.1-SNAPSHOT";

    public Knife4jConfiguration() {
        log.debug("创建配置类对象：Knife4jConfiguration");
    }

//    @Bean
//    public Docket docket() {
//        return new Docket(DocumentationType.SWAGGER_2)
//                .host(host)
//                .apiInfo(apiInfo())
//                .groupName(groupName)
//                .select()
//                .apis(RequestHandlerSelectors.basePackage(basePackage))
//                .paths(PathSelectors.any())
//                .build()
//                .extensions(openApiExtensionResolver.buildExtensions(groupName))
//                .extensions(openApiExtensionResolver.buildSettingExtensions());
//    }
//
//    private ApiInfo apiInfo() {
//        return new ApiInfoBuilder()
//                .title(title)
//                .description(description)
//                .termsOfServiceUrl(termsOfServiceUrl)
//                .contact(new Contact(contactName, contactUrl, contactEmail))
//                .version(version)
//                .build();
//    }

    @Bean
    public OpenAPI customOpenApi() {
        Contact contact = new Contact();
        contact.setName(contactName);
        contact.setEmail(contactEmail);
        contact.setUrl(contactUrl);
        return new OpenAPI()
                .info(new Info()
                        .title(title)
                        .version(version)
                        .contact(contact)
                        .description(description)
                        .termsOfService(termsOfServiceUrl)
                        .license(new License().name("Apache 2.0").url("https://springdoc.org")));
    }
}